package org.mspring.platform.api.rss.elements;

import java.util.LinkedList;
import java.util.List;

import org.mspring.platform.api.rss.writers.RSSWriter;
import org.mspring.platform.api.rss.writers.RSSWriterFactory;

import electric.xml.Element;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月26日
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public class Channel extends CategorizedElement {
    private static final long serialVersionUID = -1015304929920772270L;

    private String originalType = "rdf";
    private Image image = null;
    private TextInput textInput = null;
    private String generator;
    private List items = new LinkedList();

    public String getOriginalType() {
        return this.originalType;
    }

    protected void setOriginalType(String paramString) {
        this.originalType = paramString;
    }

    public String getFeed(String paramString) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        RSSWriter localRSSWriter = RSSWriterFactory.getWriter(paramString);
        return localRSSWriter.getFeed(this);
    }

    static Channel getChannel(Element paramElement) {
        Channel localChannel = null;
        DublinCore.init(paramElement);
        Element localElement = paramElement.getElement("channel");
        if (localElement != null) {
            localChannel = new Channel();
            String str = localElement.getParentElement().getName();
            if (str.equals("RDF"))
                localChannel.setOriginalType("rdf");
            else
                localChannel.setOriginalType(localElement.getParentElement().getAttributeValue("version"));
            localChannel.setTitle(DublinCore.getElementValue(localElement, "title"));
            localChannel.setAbout(DublinCore.getNSAttrValue(localElement, DublinCore.rdf, "about"));
            localChannel.setLink(DublinCore.getElementValue(localElement, "link"));
            localChannel.setDescription(DublinCore.getElementValue(localElement, "description"));
            localChannel.setLanguage(DublinCore.getElementValue(localElement, "language"));
            localChannel.setCopyright(DublinCore.getElementValue(localElement, "copyright"));
            localChannel.setManagingEditor(DublinCore.getElementValue(localElement, "managingEditor"));
            CategorizedElement.setCategories(localElement, localChannel);
            DublinCore.setDublinCoreElements(localElement, localChannel);
        }
        return localChannel;
    }

    public TextInput setTextInput(String paramString1, String paramString2, String paramString3, String paramString4) {
        TextInput localTextInput = new TextInput();
        localTextInput.setTitle(paramString3);
        localTextInput.setDescription(paramString2);
        localTextInput.setName(paramString4);
        localTextInput.setLink(paramString1);
        localTextInput.setAbout(paramString1);
        setTextInput(localTextInput);
        return localTextInput;
    }

    public Image setImage(String paramString1, String paramString2, String paramString3) {
        Image localImage = new Image();
        localImage.setUrl(paramString3);
        localImage.setTitle(paramString2);
        localImage.setLink(paramString1);
        localImage.setAbout(paramString3);
        setImage(localImage);
        return localImage;
    }

    public Item addItem(String link, String description, String title) {
        Item localItem = new Item();
        localItem.setTitle(title);
        localItem.setLink(link);
        localItem.setDescription(description);
        localItem.setAbout(link);
        addItem(localItem);
        return localItem;
    }

    public void addItem(Item paramItem) {
        this.items.add(paramItem);
    }

    public Image getImage() {
        return this.image;
    }

    void setImage(Image paramImage) {
        this.image = paramImage;
    }

    public TextInput getTextInput() {
        return this.textInput;
    }

    void setTextInput(TextInput paramTextInput) {
        this.textInput = paramTextInput;
    }

    public List getItems() {
        return this.items;
    }

    void setItems(List paramList) {
        if (paramList == null)
            paramList = new LinkedList();
        this.items = paramList;
    }

    public void setLink(String paramString) {
        super.setLink(paramString);
        super.setAbout(paramString);
    }

    public void addItem(int paramInt, Item paramItem) {
        this.items.add(paramInt, paramItem);
    }

    public void insertItem(Item paramItem) {
        addItem(0, paramItem);
    }

    public String getGenerator() {
        return generator;
    }

    public void setGenerator(String generator) {
        this.generator = generator;
    }

}